function FK =kuka_8dof_forwardmatics(theta,tool)
%DH参数
n=1;
%extra
% alp=[pi pi/2 0 -pi/2 pi/2 -pi/2 pi/2];
% a=[0 n*350 n*1150 n*41 0 0 0];
% d=[n*-675 0 0 n*-1200 0 n*-340 0];%这个-215是第五轴中心到第六轴中心的距离要加上第六轴中心到第七轴中心的距离，x方向的距离才正确
% offset=[0 0 pi/2 0 0 -pi/2 0];
%r2700-2
alp=[pi pi/2 0 -pi/2 pi/2 -pi/2 pi/2];
a=[0 n*330 n*1150 n*-115 0 0 0];
d=[n*-645 0 0 n*-1220 0 n*-292 0];%这个-215是第五轴中心到第六轴中心的距离要加上第六轴中心到第七轴中心的距离，x方向的距离才正确
offset=[0 0 pi/2 0 0 -pi/2 0];
theta=(deg2rad(theta)+offset);
Ti=zeros(4,4,7);
for i=1:7
    Ti(:,:,i)=[               cos(theta(i)),             -sin(theta(i)),             0,               a(i);
                   sin(theta(i))*cos(alp(i)), cos(theta(i))*cos(alp(i)),-sin(alp(i)),-d(i)*sin(alp(i));
                   sin(theta(i))*sin(alp(i)),  cos(theta(i))*sin(alp(i)), cos(alp(i)), d(i)*cos(alp(i));
                                0,                                  0,                    0,               1];

end
% FK= [1 0 0 0;0 1 0 0;0 0 1 n*26.5;0 0 0 1]*Ti(:,:,1)*Ti(:,:,2)*Ti(:,:,3)*Ti(:,:,4)*Ti(:,:,5)*Ti(:,:,6)*Ti(:,:,7)*[0 -1 0 0;-1 0 0 0; 0 0 -1 n*-248; 0 0 0 1];
% FK= [1 0 0 0;0 1 0 0;0 0 1 n*30;0 0 0 1]*Ti(:,:,1)*Ti(:,:,2)*Ti(:,:,3)*Ti(:,:,4)*Ti(:,:,5)*Ti(:,:,6)*Ti(:,:,7)*[0 -1 0 0;-1 0 0 0; 0 0 -1 n*-260; 0 0 0 1];
FK= [1 0 0 0;0 1 0 0;0 0 1 n*30;0 0 0 1]*Ti(:,:,1)*Ti(:,:,2)*Ti(:,:,3)*Ti(:,:,4)*Ti(:,:,5)*Ti(:,:,6)*Ti(:,:,7)*[0 -1 0 0;-1 0 0 0; 0 0 -1 n*-tool; 0 0 0 1];
% FK= [1 0 0 0;0 1 0 0;0 0 1 n*30;0 0 0 1]*Ti(:,:,1)*Ti(:,:,2)*Ti(:,:,3)*Ti(:,:,4)*Ti(:,:,5)*Ti(:,:,6)*Ti(:,:,7)*[0 -1 0 0;-1 0 0 0; 0 0 -1 n*-264; 0 0 0 1];

end